package com.kdgc.power.base.controller;

import com.kdgc.power.base.entity.BaseRecord;
import com.kdgc.power.base.service.BaseRecordService;
import com.kdgc.power.fw.bean.JsonMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("BaseRecord")
public class BaseRecordController {
    @Autowired
    private BaseRecordService baseRecordService;

    @RequestMapping("page")
    public Object getPage(HttpServletRequest request, int page, int rows) {
        String recordName = request.getParameter("recordName");
        return  baseRecordService.searchPage(   page, rows,recordName);
    }

    @RequestMapping("findById")
    public Map<String,Object> findById(Integer id) {
        return  baseRecordService.getMapEntity(id);
    }

    @RequestMapping("save")
    public JsonMsg save(BaseRecord entity) {
        boolean success = baseRecordService.saveOrUpdate(entity);
        return new JsonMsg(success);
    }

    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = baseRecordService.removeById(id);
        return new JsonMsg(rows == 1);
    }
}